// 导入创建store的语法
import { legacy_createStore as createStore } from 'redux'
import { fromJS } from 'immutable'
import { combineReducers } from 'redux-immutable'
// 初始化state
const defaultState = fromJS({
  msg: '不可变数据',
  obj: {
    count: 1
  }
})
// 创建reducer
function reducer(state = defaultState, action) {
  if (action.type === 'incr') {
    // return {
    //   ...state,
    //   obj: {
    //     count: state.obj.count + action.payload
    //   }
    // }
    return state.updateIn(['obj', 'count'], (val) => val + action.payload)
  }
  return state
}
// 创建store
const store = createStore(combineReducers({ reducer }))

// 导出
export default store
